// @Author EthanScriptOn
// @Desc
package extend_param_builder

import (
	"fmt"
	"gitee.com/fatzeng/srf_switch_expansion_package/extend_param_collector"
	"github.com/apache/rocketmq-client-go/v2/primitive"
)

type RocketmqProducerParamsBuilder struct {
}

func (r *RocketmqProducerParamsBuilder) Build(params interface{}) (interface{}, error) {
	producerParams, ok := params.(*extend_param_collector.RocketmqProducerParams)
	if !ok {
		return nil, fmt.Errorf("params type is not *RocketmqProducerParams")
	}
	if len(producerParams.Params) <= 0 {
		return nil, fmt.Errorf("params is empty")
	}

	buildResponse := make([]*primitive.Message, 0)
	for _, param := range producerParams.Params {
		message := new(primitive.Message)
		message.Topic = param.Topic
		message.Body = param.Body
		message.Queue = param.Queue
		message.TransactionId = param.TransactionId
		message.Compress = param.Compress
		message.Flag = param.Flag
		message.CompressedBody = param.CompressedBody
		message.Batch = param.Batch
		buildResponse = append(buildResponse, message)
	}
	return buildResponse, nil
}
